__author__ = 'bigmisspanda'
import wmi
import time
import sys



c = wmi.WMI("192.168.0.66",user ='administrator',password = 'ok')


def cpu_mem():
    
    for processor in c.Win32_Processor():
        print processor.Name.strip()
    return ''
        
def disk():

    for disk in c.Win32_LogicalDisk (DriveType=3):
             print disk.Caption,str(long(disk.Size)/1024/1024/1024)+"G","%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size))
    return ''
def memory():
    a = 0
    for Memory in c.Win32_PhysicalMemory():
        
        a = a+(int(Memory.Capacity)/1048576)
        
    print a,"MB"
    return ''

def memorydetail():
    a = 0
    wql = "select AvailableMBytes from Win32_PerfRawData_PerfOS_Memory  "
    a = c.query(wql)[0].AvailableMBytes
    print a,"MB"
    return ''

def process():

    wql = "select * from Win32_Process"
    wsql = "select * from  Win32_PerfFormattedData_PerfProc_Process "
    for process in c.query(wsql):
        name = process.Name
        print process.Name,process.percentprocessortime,process.WorkingSetPrivate+'byte'
    return ''


def product():
    wql = 'select * from Win32_Product'
    for disk in c.query(wql):
        print disk.caption
    return ''
def service():
    wsql = "select * from Win32_Service"

    for service in c.query(wsql):
        if service.State=='Running':
            print service.Caption,'-----',service.Name,service.PathName
    return ''

def cpu_use():

        for cpu in c.Win32_Processor():

            print cpu.LoadPercentage,'%'
        return ''
 

def diskio():
    wql = "select * from Win32_PerfFormattedData_PerfDisk_PhysicalDisk where Name!='Total'"
    for disk_info in  c.query(wql):
        M = 1024 * 1024
        print 'DiskMsPersec:%s DiskReadMsPersec:%s DiskWriteMsPersec:%s' % (
            int(disk_info.DiskBytesPersec) / M,
            int(disk_info.DiskReadBytesPersec) / M,
            int(disk_info.DiskWriteBytesPersec) / M
            )
    return ''


# print 'cpuuse==',cpu_use(),'jia','cpu==',cpu_mem(),'jia','disk==',disk(),'jia','memory==',memory(),'jia','process==',process(),'jia','service==',service()
print process()
